package cn.wolfcode.shop.web.controller;

import cn.wolfcode.shop.domain.UserLogin;
import cn.wolfcode.shop.service.IOrderInfoService;
import cn.wolfcode.shop.vo.JsonResultVO;
import cn.wolfcode.shop.vo.OrderVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderController {
    @Reference
    private IOrderInfoService orderInfoService;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 创建订单
     * 地址：/order/create
     * 参数：JSON
     *{
     "userAddressId":1,
     "pay":{"payType":2},
     "productSkuIds":[1,3],
     "invoice":{"invoiceType":2,"invoiceHead":1,"invoiceContent":1,"invoicePhone":"13022004622","invoiceEmail":""}
     }
     * 请求方式：post
     */
    @RequestMapping("/order/create")
    @ResponseBody
    public JsonResultVO createOrder(@RequestBody OrderVo orderVo,String token){

        UserLogin userLogin = (UserLogin) redisTemplate.opsForValue().get(token);

        orderInfoService.createOrder(orderVo, userLogin);

        return JsonResultVO.success();
    }
}
